
{% extends 'base_main.html' %}

{% block title %}
    天天生鲜-商品详情
{% endblock %}


{% block content %}
	<div class="navbar_con">
		<div class="navbar clearfix">
			<div class="subnav_con fl">
				<h1>全部商品分类</h1>	
				<span></span>			
				<ul class="subnav">
					<li><a href="{% url 'goods:list' 1 %}" class="fruit">新鲜水果</a></li>
					<li><a href="{% url 'goods:list' 2 %}" class="seafood">海鲜水产</a></li>
					<li><a href="{% url 'goods:list' 3 %}" class="meet">猪牛羊肉</a></li>
					<li><a href="{% url 'goods:list' 4 %}" class="egg">禽类蛋品</a></li>
					<li><a href="{% url 'goods:list' 5 %}" class="vegetables">新鲜蔬菜</a></li>
					<li><a href="{% url 'goods:list' 6 %}" class="ice">速冻食品</a></li>
				</ul>
			</div>
			<ul class="navlist fl">
				<li><a href="{% url 'goods:index' %}">首页</a></li>
				<li class="interval">|</li>
				<li><a href="">手机生鲜</a></li>
				<li class="interval">|</li>
				<li><a href="">抽奖</a></li>
			</ul>
		</div>
	</div>

	<div class="breadcrumb">
		<a href="">全部分类</a>
		<span>></span>
		<a href="{% url 'goods:list' goods.category_id %}">
            {% for type in category_type %}
                {% if type.0 == goods.category_id %}
                        {{ type.1 }}
                {% endif %}
            {% endfor %}
		</a>
		<span>></span>
		<a href="">商品详情</a>
	</div>

	<div class="goods_detail_con clearfix">
		<div class="goods_detail_pic fl"><img src="/media/{{ data }}"></div>

		<div class="goods_detail_list fr">
			<h3>{{ goods.name }}</h3>
			<p>{{ goods.goods_brief }}</p>
			<div class="prize_bar">
				<span class="show_pirze">¥<em id="ddf1">{{ goods.shop_price }}</em></span>
				<span class="show_unit">单  位：500g</span>
			</div>
			<div class="goods_num clearfix">
				<div class="num_name fl">数 量：</div>
				<div class="num_add fl">
					<input type="text" class="num_show fl" value="1">
					<a href="javascript:;" class="add fr" onclick="add_goods();">+</a>
					<a href="javascript:;" class="minus fr" onclick="sub_goods();">-</a>
				</div>
                <script>
                <!--加商品-->
                function add_goods(){
                    var num = $('.num_show').val()
                    var new_num = parseInt(num) + 1
                    $('.num_show').val(new_num)
                    var price = $('#ddf1').text()
                    var new_total = new_num * price
                    $('.total em').text(new_total+'元')
                }
                <!--减商品-->
                function sub_goods(){
                    var num = $('.num_show').val()
                    if(parseInt(num)>1){
                        var new_num = parseInt(num) - 1
                        $('.num_show').val(new_num)
                        var price = $('#ddf1').text()
                        var new_total = new_num * price
                        $('.total em').text(new_total+'元')
                    }
                }
                </script>
			</div>
			<div class="total">总价：<em>{{ goods.shop_price }}元</em></div>
			<div class="operate_btn">
				<a href="javascript:;" class="buy_btn">立即购买</a>
				<a href="javascript:;" class="add_cart"
                   id="add_cart"
                   onclick="add_cart({{ goods.id }});">
                    加入购物车
                </a>
			</div>


            {% csrf_token %}
            <script>
                function add_cart(id){
                    var num = $('.num_show').val()
                    var csrf = $('input[name="csrfmiddlewaretoken"]').val()
                    $.ajax({
                        url:'/cart/add_cart/',
                        type:'POST',
                        data:{'goods_id':id, 'goods_num':num},
                        headers:{'X-CSRFToken': csrf},
                        dataType:'json',
                        success:function(data){
                            if(data.code == '200'){
                                $('#show_count').text(data.count)
                            }
                        },
                        error:function(data){
                            alert('失败')
                        }
                    })
                }

            </script>
		</div>
	</div>

	<div class="main_wrap clearfix">
		<div class="l_wrap fl clearfix">
			<div class="new_goods">
				<h3>新品推荐</h3>
				<ul>
                    {% for good in new_goods %}
                    <li>
						<a href="{% url 'goods:detail' good.id %}"><img src="/media/{{ good.goods_front_image }}"></a>
						<h4><a href="{% url 'goods:detail' good.id %}">{{ good.name }}</a></h4>
						<div class="prize">￥{{ good.shop_price }}</div>
					</li>
                    {% endfor %}
				</ul>
			</div>
		</div>

		<div class="r_wrap fr clearfix">
			<ul class="detail_tab clearfix">
				<li class="active">商品介绍</li>
				<li>评论</li>
			</ul>

			<div class="tab_content">
				<dl>
					<dt>商品详情：</dt>
					<dd>{{ goods.goods_desc | safe }}</dd>
				</dl>
			</div>

		</div>
	</div>
{% endblock %}

{% block js2 %}
	<div class="add_jump"></div>

	<script type="text/javascript" src="/static/js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript">
		var $add_x = $('#add_cart').offset().top;
		var $add_y = $('#add_cart').offset().left;

		var $to_x = $('#show_count').offset().top;
		var $to_y = $('#show_count').offset().left;

		$(".add_jump").css({'left':$add_y+80,'top':$add_x+10,'display':'block'})
		$('#add_cart').click(function(){
			$(".add_jump").stop().animate({
				'left': $to_y+7,
				'top': $to_x+7},
				"fast", function() {
					$(".add_jump").fadeOut('fast',function(){
					    <!--window.location.reload()-->
					});
			});
		})
	</script>
{% endblock %}